package com.sport.mapper;


import com.sport.pojo.dto.ApplyPlayerDto;
import com.sport.pojo.dto.CreateTeamDto;
import com.sport.pojo.dto.TeamRankDto;
import com.sport.pojo.entity.*;
import com.sport.pojo.vo.TeamUserVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeamMapper {
    @Update("update user set team= 1,team_id = #{teamId} where user_id = #{userId}")
    int userIntoTeam(String userId,String teamId);
    @Select("select user_id,user_name,avatar,user_football_dan,football_position from user where team_id = #{teamId}")
    List<FootballPlayer> showAllPlayersIn(String teamId);
    @Select("select * from team")
    List<Team> showAllTeams();
    @Select("select * from team where team_name = #{teamName}")
    Team showTeamDetails(String teamName);
    @Select("select team_name,team_recommend,team_grade,team_avatar from team where team_id = #{teamId}")
    Team showTeamMessageBy(String teamId);
    @Select("select user_name as team_leader_name,team_name,team_grade,team_avatar from team join user on team.teamleader_id = user.user_id order by team_grade desc ;")
    List<TeamRankDto> getTeamRankList();
    @Insert("insert into uandt(application_user_name, application_team_id) values (#{userName},#{teamId})")
    int applyFor(String userName,String teamId);
    @Select("select application_user_name,user_football_dan,avatar from uandt join user on uandt.application_user_name = user.user_name where application_team_id = #{ApplicationTeamId}")
    List<ApplyPlayerDto> getApplyTable(String applicationTeamId);
    @Update("update user set team= 1,team_id = #{teamId} where user_name = #{userName}")
    int applyYesUserIntoTeamByName(TeamUserVo teamUserVo);
    @Delete("delete from uandt where application_team_id=#{teamId}and application_user_name=#{userName};")
    int deleteApplyMessage(TeamUserVo teamUserVo);
    @Select("select team_name,team_avatar,game_num,win_num,flat_num,failure_num,goal_num,lose_num,integral from team order by integral desc,goal_num-lose_num desc ;")
    List<LeagueScoreboardDto> showLeagueScoreboard();
    @Select("select * from team where team_name like '%${teamName}%'")
    List<Team> searchTeam(String teamName);
    @Insert("insert into team(team_id,team_name,teamleader_id,team_avatar,team_recommend,team_status,create_time) values (#{teamId},#{teamName},#{teamLeaderId},#{teamAvatar},#{teamRecommend},#{teamStatus},#{createTime})")
    int creatTeam(CreateTeamDto createTeamDto);
}
